﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CLEX.AdminUI.Service;

namespace CLEX.AdminUI.Services
{
    internal sealed class ProxyService
    {
        public void CreateSharedDatabase(SharedDatabaseData sharedDatabase)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.CreateSharedDatabase(sharedDatabase);
                proxy.Close();
            }
        }

        public void DeleteSharedDatabase(SharedDatabaseData sharedDatabase)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.DeleteSharedDatabase(sharedDatabase);
                proxy.Close();
            }
        }

        public List<SharedDatabaseData> GetAllSharedDatabases()
        {
            List<SharedDatabaseData> result;
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                result = new List<SharedDatabaseData>(proxy.GetAllSharedDatabases());
                proxy.Close();
            }
            return result;
        }

        public void UpdateSharedDatabase(SharedDatabaseData sharedDatabase)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.UpdateSharedDatabase(sharedDatabase);
                proxy.Close();
            }
        }

        public void CreateUser(UserData user)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.CreateUser(user);
                proxy.Close();
            }
        }

        public void DeleteUser(UserData user)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.DeleteUser(user);
                proxy.Close();
            }
        }

        public List<UserData> GetAllUsers()
        {
            List<UserData> result;
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                var o = proxy.GetAllUsers();
                result = new List<UserData>(o);
                proxy.Close();
            }
            return result;
        }

        public void UpdateUser(UserData user)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.UpdateUser(user);
                proxy.Close();
            }
        }

        public PasswordChangeResultData ChangeUserPassword(int userId, string oldPassword, string newPassword)
        {
            PasswordChangeResultData result;
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                result = proxy.ChangeUserPassword(userId, oldPassword, newPassword);
            }
            return result;
        }

        public void CreateFriendRequest(FriendRequestData friendRequest)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.CreateFriendRequest(friendRequest);
                proxy.Close();
            }
        }

        public void DeleteFriendRequest(FriendRequestData friendRequest)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.DeleteFriendRequest(friendRequest);
                proxy.Close();
            }
        }

        public List<FriendRequestData> GetAllFriendRequests()
        {
            List<FriendRequestData> result;
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                result = new List<FriendRequestData>(proxy.GetAllFriendRequests());
                proxy.Close();
            }
            return result;
        }

        public void UpdateFriendRequest(FriendRequestData friendRequest)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.UpdateFriendRequest(friendRequest);
                proxy.Close();
            }
        }

        public void CreateFriendship(FriendshipData friendship)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.CreateFriendship(friendship);
                proxy.Close();
            }
        }

        public void DeleteFriendship(FriendshipData friendship)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.DeleteFriendship(friendship);
                proxy.Close();
            }
        }

        public List<FriendshipData> GetAllFriendships()
        {
            List<FriendshipData> result;
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                result = new List<FriendshipData>(proxy.GetAllFriendships());
                proxy.Close();
            }
            return result;
        }

        public void UpdateFriendship(FriendshipData friendship)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.UpdateFriendship(friendship);
                proxy.Close();
            }
        }

        public void CreateDatabase(DatabaseData database)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.CreateDatabase(database);
                proxy.Close();
            }
        }

        public void DeleteDatabase(DatabaseData database)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.DeleteDatabase(database);
                proxy.Close();
            }
        }

        public List<DatabaseData> GetAllDatabases()
        {
            List<DatabaseData> result;
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                result = new List<DatabaseData>(proxy.GetAllDatabases());
                proxy.Close();
            }
            return result;
        }

        public void UpdateDatabase(DatabaseData database)
        {
            using (AdminServiceClient proxy = new AdminServiceClient())
            {
                proxy.UpdateDatabase(database);
                proxy.Close();
            }
        }
    }
}
